<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>感染上报</title>
    <%@ include file="/common/baseMeta.jsp" %>
    <link rel="stylesheet" href="/static/js/layui/css/layui.css" media="all">
    <script type="text/javascript" href="/static/js/layui/html5.min.js"></script>
    <script type="text/javascript" href="/static/js/layui/respond.min.js"></script>

    <script type="text/javascript" src="/static/js/common.js"></script>
    <script type="text/javascript" src="/static/js/dlcommon.js"></script>


    <script type="text/javascript">

        var uid = "${sysStaffEntity.uid}";//唯一标识
        var lname = "${sysStaffEntity.lname}"; //登录工号
        var uname="${sysStaffEntity.uname}"; //用户名
        var num = parseInt(10); //限制时间
        var ref = "";
        /*页面控件信息初始化*/
        $(function () {
            $("#yyinfo").height(180);
            $("#jyinfo").height(180);
            initYYinfo();
            initJyinfo();
            var strblh = getQueryStringRegExp("blh");
            var strzyh = getQueryStringRegExp("zyh");
            var PageMode = getQueryStringRegExp("PageMode");
            var Grid = getQueryStringRegExp("id");
            $.ajaxSetup({
                async: false
            });
            $.getJSON("/commapiV2", {p_dm: "Thz_jbxx_Getjbxx", blh: getQueryStringRegExp("blh")}, function (data) {
                if (data.success) {
                    SetFromValues(data.Table[0]);
                }
            }, true);

            $.ajaxSetup({
                async: true
            });
            $.ajaxSetup({
                async: false
            });
            //绑定科室医生
            $.getJSON("/commapiV2", {p_dm: "Thz_szbq_get", blh: strblh}, function (data) {
                if (data.success && data.Table.length > 0) {
                    $('#szks').combobox({
                        data: data.Table,
                        valueField: 'DM',
                        textField: 'MC'
                    });
                    $('#szks').combobox('select', data.Table[0].DM);
                    $('#zgys').combobox({
                        data: data.Table,
                        valueField: 'zgys',
                        textField: 'zgysName'
                    });
                    $('#zgys').combobox('select', data.Table[0].zgys);
                }
            }, true);

            $.ajaxSetup({
                async: true
            });
            $.ajaxSetup({
                async: false
            });
            //绑定用药信息
            $.getJSON("/commapiV2", {p_dm: "THZ_YYINFO_Get", blh: strblh}, function (data) {
                if (data.success) {
                    var griddata = {};
                    griddata.rows = data.Table;
                    griddata.total = data.totalcount;
                    $('#yyinfo').datagrid('loadData', griddata);
                }
            }, true);

            $.ajaxSetup({
                async: true
            });

            $.ajaxSetup({
                async: false
            });
            //绑定检验信息
            $.getJSON("/commapiV2", {p_dm: "Thz_byxjg_get", blh: strblh}, function (data) {
                if (data.success && data.Table.length > 0) {
                    var griddata = {};
                    griddata.rows = data.Table;
                    griddata.total = data.totalcount;
                    $('#jyinfo').datagrid('loadData', griddata);
                }
            }, true);

            $.ajaxSetup({
                async: true
            });
            SetGrbw("");
            $('#grfl').combobox({
                onChange: function () {
                    SetGrbw("");
                }
            });
            $('#grfl').combobox({
                onChange: function (param) {
                    if (param == "手术切口感染") {
                        Setssinfo(strzyh);
                    }
                    SetGrbw("");
                }
            });
            $.ajaxSetup({
                async: false
            });
            $.getJSON("/commapiV2", {p_dm: "Sys_Dictionary_Item_Get", dic_name: "侵害性操作"}, function (data) {
                if (data.success) {
                    $('#qhcz').combobox({
                        data: data.Table,
                        valueField: 'code',
                        textField: 'name',
                        multiple: true
                    });
                }
            }, true);
            $.ajaxSetup({
                async: true
            });
            $.ajaxSetup({
                async: false
            });
            $.getJSON("/commapiV2", {p_dm: "Sys_Dictionary_Item_Get", dic_name: "易感因素"}, function (data) {
                if (data.success) {
                    $('#ygys').combobox({
                        data: data.Table,
                        valueField: 'code',
                        textField: 'name',
                        multiple: true
                    });
                }
            }, true);

            $.ajaxSetup({
                async: true
            });
            if (PageMode == "Edite") {
                EditeData(Grid);
            }
        })

        function Setssinfo(strzyh) {

            $.ajaxSetup({
                async: false
            });
            $.getJSON("/commapiV2", {p_dm: "Thz_ssinfo_get", zyh: strzyh}, function (data) {
                if (data.success) {
                    $('#ssinfo').combobox({
                        data: data.Table,
                        valueField: 'ssbh',
                        textField: 'ssmc'
                    });
                    $('#ssinfo').combobox('select', data.Table[0].ssbh);
                }
            }, true);

            $.ajaxSetup({
                async: true
            });
        }
        function SetGrbw(GrbwCode) {

            $.ajaxSetup({
                async: false
            });
            $.getJSON("/commapiV2", {
                p_dm: "Sys_Dictionary_Item_GetByBz",
                bz: $("#grfl").combobox('getValue') == "" ? "其他" : $("#grfl").combobox('getValue'),
                name: "医院感染部位编码"
            }, function (data) {
                if (data.success) {
                    $('#grbw').combobox({
                        data: data.Table,
                        valueField: 'code',
                        textField: 'name'
                    });
                    if (GrbwCode != "")
                        $('#grbw').combobox('setValue', GrbwCode);
                }
            }, true);

            $.ajaxSetup({
                async: true
            });
        }
        //文本框赋值
        function SetFromValues(data) {
            for (var p in data) {
                if ($("#" + p).prop("tagName") == "INPUT") {
                    $("#" + p).textbox('setText', data[p]);
                }
                if ($("#" + p).prop("tagName") == "SELECT") {
                    $("#" + p).combobox('setValue', data[p]);
                }
            }
        }

        function initYYinfo() {
            $('#yyinfo').datagrid({
                fit: false, //自动适屏功能
                rownumbers: true,//显示行号
                singleSelect: true,//只显示一行
                remoteSort: false,
                fitColumns: true,
                sortable: false, //启用排序列
                collapsible: true,
                idField: 'YZBH',
                singleSelect: false,
                columns: [
                    [
                        {field: 'YZBH', title: '选择', width: '50px', checkbox: true, align: 'center'},
                        {field: 'KJYWMC', title: '用药名称', width: '250px', align: 'center'},
                        {field: 'KSSJ', title: '开始时间', width: '120px', align: 'center'},
                        {field: 'JSSJ', title: '结束时间', width: '120px', align: 'center'},
                    ]
                ],
            });
        }
        function initJyinfo() {
            $('#jyinfo').datagrid({
                fit: false, //自动适屏功能
                rownumbers: true,//显示行号
                singleSelect: true,//只显示一行
                pagination: false,//启用分页
                remoteSort: false,
                fitColumns: true,
                sortable: false, //启用排序列
                collapsible: true,
                idField: 'dm',
                singleSelect: false,
                columns: [
                    [
                        {field: 'dm', title: '选择', width: '50px', checkbox: true, align: 'center'},
                        {field: 'bbmc', title: '标本名称', width: '150px', align: 'center'},
                        {field: 'mc', title: '检出病原体', width: '150px', align: 'center'},
                        {field: 'cysj', title: '采样时间', width: '120px', align: 'center'},
                    ]
                ],
            });
        }
        /*数据保存*/
        function SaveData() {
            /*
             判定条件：
             1、感染部位不能为空
             2、当感染分类选择“手术切口感染”时，必须选择手术信息
             3、每月10号后只能上报当月数据
             4、感染日期不能大于上报日期
             5、重复上报：15天内病例号相同、感染部位相同、感染时间相同则视为重复上报
             */

            var strblh = getQueryStringRegExp("blh");
            $.ajaxSetup({
                async: false
            });
            var datalength = 0
            $.getJSON("/commapiV2", {
                p_dm: "Thz_Grinfo_Repeat",
                blh: strblh,
                grbw: $("#grbw").combobox('getValue'),
                grsj: $("#grsj").textbox('getText')
            }, function (data) {
                if (data.success) {
                    datalength = data.Table.length;
                }
            }, true);
            $.ajaxSetup({
                async: true
            });
            if (datalength > 0) {
                alert('重复上报感染，请检查');
                return;
            }
            if ($("#grbw").combobox('getValue') == "") {
                alert("请选择感染部位");
                return;
            }
            if ($("#grfl").combobox('getValue') == "手术切口感染" && $("#ssinfo").combobox('getValue') == "") {
                alert("请选择手术信息");
                return;
            }
            if ($("#grsj").combobox('getText') == "") {
                alert("请选择感染时间");
                return;
            }
            var myDate = new Date();
            var grsj = new Date($("#grsj").combobox('getText'))
            if (myDate.getDate() >= num && grsj.format("yyyy-MM") < myDate.format("yyyy-MM"))//10号后只能上报当月感染数据；
            {
                $("#grsj").combobox('SetText', null);
                alert("每月" + num + "号后只能上报本月感染数据！");
                return;
            }
            if (myDate.getDate() < num && grsj.getMonth() < myDate.getMonth() - 1)//10号前只能报当月及上月感染数据；
            {
                $("#grsj").combobox('SetText', null);
                alert("每月" + num + "号前只能上报上月及本月感染数据！");
                return;
            }
            var sbsj = new Date(myDate);
            if (sbsj < grsj) {
                $("#grsj").combobox('SetText', null);
                alert("感染日期不能大于上报日期！");
                return;
            }


            var Stryy = [];
            var yy_rows = $('#yyinfo').datagrid('getSelections');
            for (var i = 0; i < yy_rows.length; i++) {
                Stryy.push(yy_rows[i].YZBH);
            }
            var Strjy = [];
            var jy_rows = $('#jyinfo').datagrid('getSelections');
            for (var i = 0; i < jy_rows.length; i++) {
                Strjy.push(jy_rows[i].dm);
            }

            var PageMode = getQueryStringRegExp("PageMode");
            var Grid = getQueryStringRegExp("id");
            var postdata = {
                Thz_Grinfo: {
                    SSBH: $("#ssinfo").combobox('getValue'),
                    YGYS: $("#ygys").combobox('getText'),
                    BGSJ: sbsj.format("yyyy-MM-dd hh:mm"),
                    ZYCS: $("#zycs").textbox('getText'),
                    YYXX: Stryy.join(','),
                    GRFL: $("#grfl").combobox('getValue'),
                    WXYS: $("#qhcz").combobox('getText'),
                    GRLX: '医院感染',
                    GRBM: $("#grbw").combobox('getValue'),
                    QXMC: null,
                    ID: PageMode == "Edite" ? Grid : $.random.getGuid(),
                    SBR: lname,
                    GRSJ: $("#grsj").textbox('getText'),
                    ZYH: $("#zyh").textbox('getText'),
                    ZT: '未处理',
                    JYXX: Strjy.join(','),
                    ZGSJ: null,
                    ZGYS: $("#zgys").combobox('getValue'),
                    GRKS: $("#szks").combobox('getValue'),
                    BHYY: null,
                    GRZG: null,
                    BLH: getQueryStringRegExp("blh")
                }
            }
            if (PageMode == "Edite") {
                delete postdata.Thz_Grinfo["SBR"];
                delete postdata.Thz_Grinfo["BGSJ"];
            }
            dLong.postajax("/commapiV2?p_dm=Thz_Grinfo_Add", postdata, function (data) {
                $.getJSON("/commapiV2", {
                    p_dm: "Tys_Grinfo_UpdateZt",
                    zt:"已上报",
                    blh:getQueryStringRegExp("blh"),
                    czr:uname
                }, function (data) {
                    if (data.success) {

                    }
                }, true);
                alert("保存成功");
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            })
        }
        /*数据编辑赋值*/
        function EditeData(Grid) {
            //获取感染信息
            $.getJSON("/commapiV2", {p_dm: "Thz_GrinfoEdite_Get", id: Grid}, function (data) {
                if (data.success) {
                    $("#grfl").combobox('setValue', data.Table[0].GRFL);
                    SetGrbw(data.Table[0].GRBM);
                    $("#grbw").combobox('setValue', data.Table[0].GRBM);
                    $("#grsj").textbox('setValue', data.Table[0].GRSJ);
                    $("#szks").combobox('setValue', data.Table[0].GRKS);
                    $("#zgys").combobox('setValue', data.Table[0].ZGYS);

                    $.each($("#yyinfo").datagrid("getRows"), function (index, value) {
                        if (contains(data.Table[0].YYXX.split(','), value["YZBH"])) {
                            $("#yyinfo").datagrid("selectRow", index);
                        }
                    })
                    $.each($("#jyinfo").datagrid("getRows"), function (index, value) {
                        if (contains(data.Table[0].JYXX.split(','), value["dm"])) {
                            $("#jyinfo").datagrid("selectRow", index);
                        }
                    })
                    $("#qhcz").combobox('setText', data.Table[0].WXYS);
                    $("#ygys").combobox('setText', data.Table[0].YGYS);
                    $("#ssinfo").combobox('setValue', data.Table[0].SSBH == "null" ? "" : data.Table[0].SSBH);
                }
            }, true);
        }

    </script>
</head>
<body style="overflow-y: scroll; overflow-x: hidden">
<form action="">
    <div class="layui-container">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 5px;">
            <legend>基本信息</legend>
        </fieldset>
        <div class="layui-row">
            <div class="layui-col-md12">
                <div class="layui-row grid-demo">
                    <div class="layui-col-md1">
                        住院号：
                    </div>
                    <div class="layui-col-md3">
                        <input id="zyh" name="zyh" class="easyui-textbox" data-options="readonly:true"
                               style="width:170px">
                    </div>
                    <div class="layui-col-md1">
                        患者姓名：
                    </div>
                    <div class="layui-col-md3" >
                        <input id="hzxm" name="hzxm" class="easyui-textbox" data-options="readonly:true"
                               style="width:170px">
                    </div>
                    <div class="layui-col-md1">
                        性别：
                    </div>
                    <div class="layui-col-md3">
                        <input id="xb" name="xb" class="easyui-textbox" data-options="readonly:true"
                               style="width:170px">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-row " style="margin-top: 10px;">
            <div class="layui-col-md12">
                <div class="layui-row grid-demo">
                    <div class="layui-col-md1">
                        住院次数：
                    </div>
                    <div class="layui-col-md3">
                        <input id="zycs" name="zycs" class="easyui-textbox" data-options="readonly:true"
                               style="width:170px">
                    </div>
                    <div class="layui-col-md1">
                        年龄：
                    </div>
                    <div class="layui-col-md3">
                        <input id="nl" name="nl" class="easyui-textbox" data-options="readonly:true"
                               style="width:170px">
                    </div>
                    <div class="layui-col-md1">
                        床位号：
                    </div>
                    <div class="layui-col-md3">
                        <input id="cwh" name="cwh" class="easyui-textbox" data-options="readonly:true"
                               style="width:170px">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-row " style="margin-top: 10px;">
            <div class="layui-col-md12">
                <div class="layui-row grid-demo">
                    <div class="layui-col-md1">
                        入院时间：
                    </div>
                    <div class="layui-col-md3">
                        <input id="ryrq" name="ryrq" class="easyui-textbox" data-options="readonly:true"
                               style="width:170px">
                    </div>
                    <div class="layui-col-md1">
                        所在科室：
                    </div>
                    <div class="layui-col-md3">
                        <select id="szks" name="szks" class="easyui-combobox" style="width:170px">
                        </select>
                    </div>
                    <div class="layui-col-md1">
                        主管医生：
                    </div>
                    <div class="layui-col-md3">
                        <select id="zgys" name="zgys" class="easyui-combobox" style="width:170px">
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>感染信息</legend>
        </fieldset>

        <div class="layui-row " style="margin-top: 0px;">
            <div class="layui-col-md12">
                <div class="layui-row grid-demo">
                    <div class="layui-col-md1">
                        感染分类：
                    </div>
                    <div class="layui-col-md3">
                        <select id="grfl" name="grfl" class="easyui-combobox" data-options="required:true"
                                style="width:170px">
                            <option value='术后肺炎'>术后肺炎</option>
                            <option value='呼吸机相关感染'>呼吸机相关感染</option>
                            <option value='中心静脉插管相关感染'>中心静脉插管相关感染</option>
                            <option value='泌尿道插管相关感染'>泌尿道插管相关感染</option>
                            <option value='手术切口感染'>手术切口感染</option>
                            <option value='其他' selected="selected">其他</option>
                        </select>
                    </div>
                    <div class="layui-col-md1">
                        感染部位：
                    </div>
                    <div class="layui-col-md3">
                        <select id="grbw" name="grbw" data-options="required:true" class="easyui-combobox"
                                style="width:170px">
                        </select>
                    </div>
                    <div class="layui-col-md1">
                        感染时间：
                    </div>
                    <div class="layui-col-md3">
                        <input id="grsj" name="grsj" class="easyui-datetimebox"
                               data-options="required:true,showSeconds:false" style="width:170px">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-row " style="margin-top: 10px;">
            <div class="layui-col-md12">
                <div class="layui-row grid-demo">
                    <div class="layui-col-md1">
                        手术信息：
                    </div>
                    <div class="layui-col-md11">
                        <input id="ssinfo" name="ssinfo" class="easyui-combobox" style="width:330px">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-row " style="margin-top: 10px;">
            <div class="layui-col-md12">
                <div class="layui-row grid-demo">
                    <div class="layui-col-md1">
                        侵害操作：
                    </div>
                    <div class="layui-col-md5">
                        <input id="qhcz" name="qhcz" class="easyui-combobox" style="width:330px">
                    </div>
                    <div class="layui-col-md1">
                        易感因素：
                    </div>
                    <div class="layui-col-md5">
                        <input id="ygys" name="ygys" class="easyui-combobox" style="width:330px">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-row " style="margin-top: 10px;">
            <div class="layui-col-md12">
                <div class="layui-row grid-demo">
                    <div class="layui-col-md1">
                        检验信息：
                    </div>
                    <div class="layui-col-md11">
                        <table id="jyinfo" name="jyinfo" class="datagrid" style="width:100%"></table>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-row " style="margin-top: 10px;">
            <div class="layui-col-md12">
                <div class="layui-row grid-demo">
                    <div class="layui-col-md1">
                        用药信息：
                    </div>
                    <div class="layui-col-md11">
                        <table id="yyinfo" name="yyinfo" class="datagrid" style="width:100%"></table>
                    </div>
                </div>
            </div>
        </div>


    </div>
</form>
</body>
</html>